<?php
/**
 * Created by PhpStorm.
 * User: Dave
 * Date: 2018/7/27
 * Time: 14:31
 */

namespace Biz\service\activity;

use Biz\model\activity\AllActivityGoods as mAllActivityGoods;
use Biz\model\activity\AllActivitySku as mAllActivitySku;
use Biz\module\Classes\adm\AllActivityInfo as clsAllActivityInfo;
use Doraemon\pockets\publicTrait\CheckConstants;
use Biz\pockets\constInterface\ActivityInfo;
use Biz\cache\AllActivity as cAllActivity;
use Biz\cache\AllActivityStock as cAllActivityStock;
use Doraemon\tools\HhzClient as tHhzClient;
use Biz\module\Classes\User;

/**
 *
 *
 * !!! 调用该类操作数据库的方法, 需要在调用的时候开始事务 !!!
 *
 *
 * **/
class AllActivityInfo implements ActivityInfo
{
    use CheckConstants;
    const STARTING_STATUS_KEY = 'starting';
    const PREVIEW_STATUS_KEY = 'preview';
    const REDUNDANCY_KEY = 'redundancy'; // 冗余数据

    public static function admUpdateActivitySkuInfo($activityId, $typeId, $activitySkuData)
    {
        clsAllActivityInfo::admUpdateActivitySkuInfo($activityId, $typeId, $activitySkuData);
    }

    /*
     * 修改goods信息相关的数据
     * activityID和type 修改存在的数据 最后将不存在的数据置为删除状态
     * @return true | false
     * **/
    public static function admUpdateActivityInfo($activityId, $typeId, $activityGoodsData, $activitySkuData, $type, $isDel = true)
    {
        self::verfyActivitiType($type);

        return clsAllActivityInfo::admUpdateActivityInfo($activityId, $typeId, $activityGoodsData, $activitySkuData, $isDel);
    }

    // 修改活动属性相关信息,比如开始时间结束时间
    public static function admUpdateActivityAttr($activityId, $typeId, array $activityAttr, $type)
    {
        self::verfyActivitiType($type);

        return clsAllActivityInfo::admUpdateActivityAttr($activityId, $typeId, $activityAttr);
    }

    /*
     * 删除活动
     * 需要传递 type 和 activityId
     * @param $activityId 活动ID
     * $param $type 类型引文名称
     * $param $typeId 类型id
     * @return true | false
     * **/
    public static function admDelActivityInfo($activityId, $typeId, $type)
    {
        self::verfyActivitiType($type);

        return clsAllActivityInfo::admDelActivityInfo($activityId, $typeId);
    }

    /*
     * 删除活动商品
     * **/
    public static function admDelActivityByGoodsId($activityId, $typeId, $goodsId, $type)
    {
        self::verfyActivitiType($type);

        return clsAllActivityInfo::admDelActivityByGoodsId($activityId, $typeId, $goodsId);
    }

    /*
     * 删除活动sku
     * **/
    public static function admDelActivityBySkuId($activityId, $typeId, $goodsId, $skuId, $type)
    {
        self::verfyActivitiType($type);

        return clsAllActivityInfo::admDelActivityBySkuId($activityId, $typeId, $goodsId, $skuId);
    }

    private static function verfyActivitiType($type)
    {
        if (!self::checkConstants(self::_CONST_ACTIVITY_TYPE_PREFIX, $type)) {
            throw new \Exception("请求参数异常", __LINE__);
        }
    }
}